package com.lanhao.aot.bean.scope;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lanhao.aot.bean.scope.SingletonBeanScopeService;

@RestController
@RequestMapping("/scope")
public class SpringBeanScopeConstroller {
	@Autowired
	private SingletonBeanScopeService singletonBeanService;

	@GetMapping("/setLocalVariable")
	public ResponseEntity<?> setLocalVariable() {
		String localVariable = singletonBeanService.setLocalVariable();
		return new ResponseEntity<>("赋值完成后，局部变量值：" + localVariable, HttpStatus.OK);
	}

	@GetMapping("/setThreadLocalVariable")
	public ResponseEntity<?> setThreadLocalVariable() {
		String threadLocalVariable = singletonBeanService.setThreadLocalVariable();
		return new ResponseEntity<>("赋值完成后，ThreadLocal变量值：" + threadLocalVariable, HttpStatus.OK);
	}

	@GetMapping("/getLocalVariable")
	public ResponseEntity<?> getLocalVariable() {
		String localVariable = singletonBeanService.getLocalVariable();
		return new ResponseEntity<>(localVariable, HttpStatus.OK);
	}

	@GetMapping("/getThreadLocalVariable")
	public ResponseEntity<?> getThreadLocalVariable() {
		String threadLocalVariable = singletonBeanService.getThreadLocalVariable();
		return new ResponseEntity<>(threadLocalVariable, HttpStatus.OK);
	}
}
